<?php

namespace app\member\controller;

use think\admin\Controller;
use think\admin\service\AdminService;
use think\admin\helper\QueryHelper;
use app\member\model\ImsEweiShopMember;
use app\member\model\ImsEweiShopMemberMessageLog;

use think\admin\model\SystemAuth;
use think\admin\model\SystemBase;
use think\admin\model\SystemUser;
use think\facade\Request;

class Index extends Controller
{
    public function index()
    {
        /*! 判断当前会员的登录状态 */
        $this->login = AdminService::isLogin();
        /*! 菜单为空且未登录跳转到登录页 */
        
        // $this->title = '会员管理';
        $this->type = $this->get['type'] ?? '0';
        ImsEweiShopMember::mQuery()->layTable(function () {
            $this->title = '会员管理';
        }, function (QueryHelper $query) {
            // 加载对应数据列表
            $query->where(['uniacid' => 2]);

            // 数据列表搜索过滤
            $query->equal('status,mobile,openid')->dateBetween('jointime');
            $query->like('content|nickname|realname|mobile|openid#keywords');
        });
        $this->fetch();
    }

    /**
     * 添加系统会员
     * @auth true
     */
    public function add()
    {
        ImsEweiShopMember::mForm('form');
    }

    /**
     * 编辑系统会员
     * @auth true
     */
    public function edit()
    {
        ImsEweiShopMember::mForm('form');
    }

    /**
     * 发送消息
     * @auth true
     */
    public function send()
    {
        $this->to_uid = Request::param('id');
        ImsEweiShopMemberMessageLog::mForm('send');
    }

    /**
     * 删除系统会员
     * @auth true
     */
    public function remove()
    {
        $this->_checkInput();
        ImsEweiShopMemberMessageLog::mDelete();
    }

    /**
     * 修改会员状态
     * @auth true
     */
    public function status()
    {
        $this->_checkInput();
        ImsEweiShopMember::mSave($this->_vali([
            'status.in:0,1'  => '状态值范围异常！',
            'status.require' => '状态值不能为空！',
        ]));
    }

    /**
     * 检查输入变量
     */
    private function _checkInput()
    {
        if (in_array('10000', str2arr(input('id', '')))) {
            $this->error('系统超级账号禁止删除！');
        }
    }

}
